﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Web;

namespace Sprint1.Logic
{
    public class LogManager
    {
        public static void LogException(Exception exception)
        {
            StringBuilder message = new StringBuilder();
            do{
                message.Append("Exception Type "+Environment.NewLine);
                message.Append(exception.GetType().Name);
                message.Append(Environment.NewLine +Environment.NewLine);
                message.Append("Message"+Environment.NewLine);
                message.Append(exception.Message+Environment.NewLine+Environment.NewLine);
                message.Append("Staack Trace"+Environment.NewLine);
                message.Append(exception.StackTrace+Environment.NewLine+Environment.NewLine);
                exception = exception.InnerException;
            }while(exception!=null);
           // string constr = ConfigurationManager.ConnectionStrings["StudyDatabaseEntities"].ConnectionString;
           // string constr = "Server=tcp:izbd605fnd.database.windows.net,1433;Database=StudyDatabase;User ID=StudyDB@izbd605fnd;Password=SWEstudy12345;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;";
            string constr = "Server=StudyDb.mssql.somee.com;Database=StudyDb;User ID=swe2studyproject_SQLLogin_1;Password=qu79tkhgan;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;";
          
            SqlConnection connection = new SqlConnection(constr);
            SqlCommand command = new SqlCommand("InsertExceptionLog",connection);
            command.CommandType = System.Data.CommandType.StoredProcedure;
            SqlParameter param = new SqlParameter("@ExceptionMessage",message.ToString());
            command.Parameters.Add(param);
            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }
    }
}